package com.teach;
import java.util.Scanner;

public class Demo07 implements Runnable {

	public static void main(String[] args) {
		Demo07 demo07 = new Demo07();
		Thread t = new Thread(demo07,"线程一");
		t.setDaemon(true);
		t.start();
		t = new Thread(demo07,"线程二");
		t.setDaemon(true);
		t.start();
		
		Scanner sc = new Scanner(System.in);
		while(!sc.nextLine().equals("exit")){
			synchronized (demo07) {
//				demo07.notify();
				demo07.notifyAll();
			}
		}
	}

	@Override
	public void run() {
		synchronized (this) {
			for(int i=1;i<100;i++){
				System.out.println(Thread.currentThread().getName()+":"+i);
				if(i%10==0){
					try {
						this.wait();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
